package me.zhengjie.modules.system.rest.machine;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.zhengjie.base.Code;
import me.zhengjie.modules.system.domain.req.SysUserMerchantReqDTO;
import me.zhengjie.modules.system.domain.req.SysUserMerchantReqQueryDTO;
import me.zhengjie.modules.system.domain.rsp.SysUserMerchantRspDTO;
import me.zhengjie.modules.system.service.SysUserMerchantService;
import me.zhengjie.utils.PageResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * @author wx
 * @email
 * @date 2025-02-24 14:56:12
 */
@RestController
@RequestMapping("sysUserMerchant")
@Api(tags = "商户")
public class SysUserMerchantController {

    @Resource
    private SysUserMerchantService sysUserMerchantService;

    /**
     * 列表
     */
    @ApiOperation(value = "列表")
    @PostMapping("/page")
    public PageResult<SysUserMerchantRspDTO> page(@RequestBody SysUserMerchantReqQueryDTO reqQueryDTO) {
        return sysUserMerchantService.findAll(reqQueryDTO);
    }


    /**
     * 保存
     */
    @ApiOperation(value = "保存")
    @PostMapping("/save")
    public ResponseEntity<Boolean> save(@RequestBody SysUserMerchantReqDTO reqDTO) {
        sysUserMerchantService.save(reqDTO);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    /**
     * 修改
     */
    @ApiOperation(value = "修改")
    @PostMapping("/update")
    public ResponseEntity<Boolean> update(@RequestBody SysUserMerchantReqDTO reqDTO) {
        sysUserMerchantService.update(reqDTO);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除")
    @PostMapping("/delete")
    public ResponseEntity<Boolean> delete(@RequestBody Code code) {
        sysUserMerchantService.delete(code);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    /**
     * 主键查询
     */
    @ApiOperation(value = "主键查询")
    @PostMapping("/findById")
    public ResponseEntity<SysUserMerchantRspDTO> findById(@RequestBody Code code) {
        return new ResponseEntity<>(sysUserMerchantService.findById(code), HttpStatus.OK);
    }
}
